﻿Public Class FormOut
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Dim objprodinfo As New clsProdInfo
    Dim objJlMst As New clsJlMst
    Dim objAutoNumber As New clsAutoNumber
    Private Sub FormOut_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub txtBarCode_KeyDown(sender As Object, e As KeyEventArgs) Handles txtBarCode.KeyDown
        If e.KeyCode = Keys.Enter Then
            Search()
        End If
    End Sub


    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        Search()
    End Sub

    Private Sub Search()
        If String.IsNullOrEmpty(txtBarCode.Text.Trim()) Then Exit Sub
        Dim dtt As DataTable = objprodinfo.selectProdInfo(txtBarCode.Text.Trim) '还需增加查询条件
        If dtt.Rows.Count = 1 Then
            Dim dr As DataRow = dtt.Rows(0)
            If dr("jp_type").Equals(DBNull.Value) Or dr("jp_type").Equals(String.Empty) Then
                MsgBox("未获取到胶片规格型号", vbYes, "提示")
                Exit Sub
            Else
                Dim dtobjJlMstJp As DataTable = objJlMst.getListByType("胶片", dr("jp_type"))
                If dtobjJlMstJp.Rows.Count = 1 Then
                    txt_mst_value_jp.Text = dtobjJlMstJp.Rows(0)("mst_value")
                    txtCk_all_weight_jp.Text = dtobjJlMstJp.Rows(0)("cur_weight")
                Else
                    txt_mst_value_jp.Text = String.Empty
                    txtCk_all_weight_jp.Text = "0"
                End If
                Dim dtobjJlMstBhj As DataTable = objJlMst.getListByType("保护胶")
                If dtobjJlMstBhj.Rows.Count = 1 Then
                    txt_mst_value_bhj.Text = dtobjJlMstBhj.Rows(0)("mst_value")
                    txtCk_all_weight_bhj.Text = dtobjJlMstBhj.Rows(0)("cur_weight")
                Else
                    txt_mst_value_bhj.Text = String.Empty
                    txtCk_all_weight_bhj.Text = "0"
                End If
            End If
        Else
            MsgBox("未检索到此生产编号", vbYes, "提示")
        End If
    End Sub

    Private Sub txt_MouseDown(sender As Object, e As MouseEventArgs) Handles ck_weight_jp.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

    Private Sub btnOut_Click(sender As Object, e As EventArgs) Handles btnOut.Click
        If String.IsNullOrEmpty(txtBarCode.Text.Trim()) Then
            MsgBox("请扫描或输入标签号", vbYes, "提示")
            Exit Sub
        End If

        If String.IsNullOrEmpty(txt_mst_value_jp.Text.Trim()) Then
            MsgBox("未获取到胶片规格型号", vbYes, "提示")
            Exit Sub
        End If

        If String.IsNullOrEmpty(txt_mst_value_bhj.Text.Trim()) Then
            MsgBox("未获取到保护胶规格型号", vbYes, "提示")
            Exit Sub
        End If

        If ck_weight_jp.Value > txtCk_all_weight_jp.Value Then
            MsgBox("胶片出库重量大于胶片库存数量！", vbYes, "提示")
            Exit Sub
        End If
        If ck_weight_bhj.Value > txtCk_all_weight_bhj.Value Then
            MsgBox("保护胶出库重量大于保护胶库存数量！", vbYes, "提示")
            Exit Sub
        End If
        If ck_weight_jp.Value <= 0 Then
            MsgBox("胶片出库重量需大于0", vbYes, "提示")
            Exit Sub
        End If
        If ck_weight_bhj.Value <= 0 Then
            MsgBox("保护胶出库重量需大于0", vbYes, "提示")
            Exit Sub
        End If
        If MsgBox("确认要进行出库吗？", vbYesNo, "提示") = vbYes Then
            Dim code As String = Now.ToString("yyyyMMdd") & "-" & objAutoNumber.getNextKeyNo("jl_ck_code", "jlckAutoNumber")
            Dim en As New entityjl_ck
            en.prod_id = txtBarCode.Text.Trim()
            en.batch_no = String.Empty
            en.mst_value = txt_mst_value_jp.Text.Trim()
            en.xj_pgd_code = String.Empty
            en.out_weight = ck_weight_jp.Value
            en.location = String.Empty
            en.mst_value_bhj = txt_mst_value_bhj.Text.Trim()
            en.out_weight_bhj = ck_weight_bhj.Value
            Dim rtn As Integer = objJlMst.outCk(code, en, usr)
            If rtn <> -2 Then
                objAutoNumber.setNextKeyNo("jl_ck_code", "jlckAutoNumber")
                MsgBox("出库成功", vbYes, "提示")
                CType(Owner, FormMain).initData()
            Else
                MsgBox("出库失败", vbYes, "提示")
            End If
        End If
    End Sub

End Class

Public Class entityjl_ck
    Public prod_id As String   ' 标签号
    Public batch_no As String   ' 批次
    Public location As String   ' 库位号
    Public out_weight As Decimal   ' 出库重量
    Public mst_value As String   ' 规格型号
    Public out_weight_bhj As Decimal   ' 出库重量
    Public mst_value_bhj As String   ' 规格型号
    Public xj_pgd_code As String    '派工单号
End Class